<template>
	<view class="info">
		<img-slide :imgUrlList="regionInfo.regionImgs"></img-slide>

		<view class="box1">
			<view class="head">
				<view class="title">{{regionInfo.regionName}}</view>
				<view class="price">{{regionInfo.regionPrice}}/h</view>
			</view>
			<view class="state">{{regionInfo.regionState}}</view>
			<view class="text1"><text class="key">加入时间:</text>{{regionInfo.regionDate}}</view>
			<view class="text1"><text class="key">简介:</text>{{regionInfo.regionIntroduce}}</view>
			<view style="align-self: center;" class="btn" v-if="regionType==1">
				<view class="button" @click="order">立即预约</view>
				<view class="button" @click="start">立即洗浴</view>
			</view>
			<view style="align-self: center;" class="btn" v-else-if="regionType==2">
				<view class="button" @click="start">立即洗浴</view>
			</view>
		</view>
	</view>
</template>

<script>
	import imgSlide from '../../components/img-slide.vue';
	export default {
		components: {
			imgSlide
		},
		data() {
			return {
				regionId: 0,
				regionInfo: {}
			};
		},
		onLoad({
			regionId
		}) {
			this.regionId = regionId || 1
			this.getRegionInfo()
		},
		computed: {
			regionType() {
				let type = 1
				if (this.regionInfo.regionState == '空闲') {
					type = 1
				} else if (this.regionInfo.regionState == '使用中') {
					type = 0
				} else if (this.regionInfo.regionState == '已预约') {
					if (this.$store.getters['getOrderData'].userId == this.$store.getters['getUserInfoData'].userId && this.$store.getters[
							'getOrderData'].regionId == this.regionId) {
						type = 2
					} else {
						type = 0
					}
				} else {

				}
				return type
			}
		},
		methods: {
			getRegionInfo() {
				this.$api.getRegionInfo({
					regionId: this.regionId
				}).then(res => {
					if (res.code) {
						this.regionInfo = res.data
					}
				})
			},
			order() {
				if (JSON.stringify(this.$store.getters['getOrderData']) != '{}') {
					this.$comm.errorToShow('已存在预约澡堂')
					return
				}
				if (this.$store.getters['getTokenData']) {
					this.$comm.navigateTo('/pages/order/order?regionId=' + this.regionInfo.regionId)
				} else {
					this.$comm.jumpToLogin()
				}
			},
			start() {
				if (JSON.stringify(this.$store.getters['getOrderData']) != '{}' && this.$store.getters['getOrderData'].userId !=
					this.$store.getters['getUserInfoData'].userId) {
					this.$comm.errorToShow('已存在预约澡堂')
					return
				}
				if (this.$store.getters['getTokenData']) {
					this.$comm.navigateTo('/pages/start/start?regionId=' + this.regionInfo.regionId + '&type=' + this.regionType)
				} else {
					this.$comm.jumpToLogin()
				}
			}
		}
	}
</script>

<style lang="scss">
	page {
		display: flex;
		flex-direction: column;
		align-items: left;
		background-color: #f8f8f8;
	}

	.info {
		.key {
			color: #CCCCCC;
		}

		.title {
			width: 80%;
			color: rgba(80, 80, 80, 1);
			font-size: 28px;
			line-height: 150%;
			text-align: left;
			font-weight: bold;
			margin-top: 30rpx;
			margin-left: 30rpx;

		}

		.state {
			color: red;
			margin: 10upx 0upx;
			font-size: 34upx;
			width: 90%;
			text-align: left;
			align-self: center;

		}

		.price {
			font-size: 14px;
			line-height: 150%;
			margin-right: 30rpx;
			margin-top: 20rpx;
			height: 100%;
			color: red;
			font-weight: bold;
		}

		.text1 {
			margin: 10upx 0upx;
			width: 90%;
			color: rgba(80, 80, 80, 1);
			font-size: 14px;
			line-height: 150%;
			text-align: left;
			align-self: center;
		}

		.box1 {
			width: 100%;
			top: 320rpx;
			color: rgba(80, 80, 80, 1);
			background-color: #f5f5f5;
			border-radius: 16px;
			font-size: 14px;
			line-height: 150%;
			text-align: center;
			position: absolute;
			display: flex;
			flex-direction: column;
		}

		.head {
			display: flex;
			flex-direction: row;
			margin-bottom: 20rpx;
			justify-content: space-between;
			align-items: center;
		}

		.date {
			color: rgba(80, 80, 80, 1);
			font-size: 36rpx;
			line-height: 150%;
			text-align: left;
			font-weight: bold;
			margin-left: 30rpx;
		}

		.dateline {
			display: flex;
			flex-direction: row;
			margin-top: 30rpx;
			margin-bottom: 20rpx;
		}

		.btn {
			right: 0;
			left: 0;
			margin: auto;
			position: fixed;
			bottom: 200upx;
			display: flex;
			justify-content: center;
			align-items: center;
		}

		.button {
			width: 171px;
			height: 44px;
			color: rgba(255, 255, 255, 1);
			background-color: rgba(64, 169, 255, 1);
			border-radius: 20px;
			font-size: 20px;
			line-height: 150%;
			font-weight: bold;
			display: flex;
			align-items: center;
			justify-content: center;
			margin: 0upx 10upx;

		}
	}
</style>
